package com.yaoxuguang.concurrence.wait_notify.thread_commumication_pipeline;

import java.io.IOException;
import java.io.PipedReader;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.wait_notify.thread_commumication_pipeline
 * @Description: 通过管道进行通讯--字符流--读取数据
 * @date 2018年12月24日11:03
 */
public class ReadData {
    public void readData(PipedReader pipedReader){
        try {
            System.out.println("read...");
            char [] byteArray = new char[20];
            int readLength = pipedReader.read(byteArray);
            while (readLength != -1){
                String newData = new String(byteArray,0,readLength);
                System.out.print(newData);
                readLength = pipedReader.read(byteArray);
            }
            System.out.println();
            pipedReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
